home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / Buttons.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  12.7 KB  |  556 lines  |  [TEXT/CWIE]

  1. { Buttons.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit Buttons;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     EverythingEngine,
  21.     EverythingDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Buttons        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mCapInvisibleLabel:    ControlHandle;
  30.         mInvisibleHandle:        ControlHandle;
  31.         mStandardHandle:        ControlHandle;
  32.         mDefaultHandle:        ControlHandle;
  33.         mBevelHandle:        ControlHandle;
  34.         mButtonHandle:        ControlHandle;
  35.         mNextHandle:        ControlHandle;
  36.         mNext2Handle:        ControlHandle;
  37.         mGraphicHandle:        ControlHandle;
  38.         mCapcicnLabel:    ControlHandle;
  39.         mRightHandle:        ControlHandle;
  40.         mCapicl8Label:    ControlHandle;
  41.         mLightHandle:        ControlHandle;
  42.         mCapICNLabel:    ControlHandle;
  43.         mRight2Handle:        ControlHandle;
  44.         mCapicl9Label:    ControlHandle;
  45.         mButton2Handle:        ControlHandle;
  46.         mRight3Handle:        ControlHandle;
  47.         mCapPICTLabel:    ControlHandle;
  48.         mRect3DHandle:        ControlHandle;
  49.         mLeftIconHandle:        ControlHandle;
  50.         mRightIconHandle:        ControlHandle;
  51.         mTitledPICTHandle:        ControlHandle;
  52.  
  53.     {methods}
  54.         Procedure Initialize; Override;
  55.  
  56.         Procedure Open        (inDoc:        EverythingDoc;
  57.                              inData:    DDocData);
  58.         Procedure Close; Override;
  59.  
  60.         Procedure Control    (whichControl:    ControlHandle;
  61.                               whichPart:        integer;
  62.                              where:            Point); Override;
  63.         Procedure MouseIn    (where:            Point;
  64.                              modifiers:        integer); Override;
  65.         Procedure TypeIn    (charCode:        SInt16); Override;
  66.         Procedure ExitCurField; Override;
  67.         Procedure DataChanged    (inDataID:    longint); Override;
  68.         Procedure Resize; Override;
  69.         Procedure Scroll    (newValue:        integer;
  70.                              oldValue:        integer); Override;
  71.  
  72.         Function  GetEngine: EverythingEngine;
  73.  
  74. {$ifc false}
  75.         Procedure UpdateMenus; Override;
  76. {$endif}
  77.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  78.  
  79.         Procedure DoUndo;
  80.         Procedure DoCut;
  81.         Procedure DoCopy;
  82.         Procedure DoPaste;
  83.         Procedure DoClear;
  84.         Procedure DoSelectAll;
  85.         Procedure DoShowClipboard;
  86.  
  87.     end;
  88.  
  89. {----------}
  90. Procedure CreateButtons    (inDoc:        EverythingDoc;
  91.                              inData:    DDocData);
  92.  
  93. {----------}
  94. Implementation
  95.  
  96. Uses
  97.     Globals,
  98.     ResourceDefs,
  99.     DoScrap,
  100.     Scrolling,
  101.     ControlUtils,
  102.     Miscellany;
  103.  
  104. const
  105.     kCapInvisibleLabel        = 1;
  106.     kInvisibleButton        = 2;
  107.     kStandardButton        = 3;
  108.     kDefaultButton        = 4;
  109.     kBevelBox        = 5;
  110.     kButtonButton        = 6;
  111.     kNextButton        = 7;
  112.     kNext2Button        = 8;
  113.     kGraphicBox        = 9;
  114.     kCapcicnLabel        = 10;
  115.     kRightButton        = 11;
  116.     kCapicl8Label        = 12;
  117.     kLightButton        = 13;
  118.     kCapICNLabel        = 14;
  119.     kRight2Button        = 15;
  120.     kCapicl9Label        = 16;
  121.     kButton2Button        = 17;
  122.     kRight3Button        = 18;
  123.     kCapPICTLabel        = 19;
  124.     kRect3DButton        = 20;
  125.     kLeftIconButton        = 21;
  126.     kRightIconButton        = 22;
  127.     kTitledPICTButton        = 23;
  128.  
  129. {----------}
  130. Procedure CreateButtons (
  131.     inDoc:        EverythingDoc;
  132.     inData:        DDocData);
  133. var
  134.     winObj:        Buttons;
  135. begin
  136.     winObj := nil;
  137.     New (winObj);
  138.  
  139.     if winObj <> nil then begin
  140.         winObj.Initialize;
  141.         winObj.Open (inDoc, inData);
  142.     end;
  143. end;
  144.  
  145. {----------}
  146. Procedure Buttons.Initialize;
  147. begin
  148.     Inherited Initialize;
  149. end;
  150.  
  151. {----------}
  152. Function  Buttons.GetEngine: EverythingEngine;
  153. begin
  154.     GetEngine := EverythingEngine (mDoc.mEngine);
  155. end;
  156.  
  157. {----------}
  158. Procedure Buttons.Open (
  159.     inDoc:        EverythingDoc;
  160.     inData:        DDocData);
  161. var
  162.     window:        WindowPtr;
  163.     wftb:        Handle;
  164.     errCode:    OSErr;
  165. begin
  166.     mDoc := inDoc;
  167.     mData := inData;
  168.     mData.AddResponder (self);
  169.  
  170.     window := GetNewCWindow (WIND_Buttons, nil, WindowPtr (-1));
  171.     if inDoc.mEngine.GetFilename <> '' then begin
  172.         SetWTitle (window, inDoc.mEngine.GetFilename);
  173.     end;
  174.     mWindow := window;
  175.     EverythingDoc (mDoc).mButtonsPtr := window;
  176.  
  177.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  178.     SetWRefCon (window, ord4 (self));
  179.     SetPort (window);
  180.     SetInfo (window);
  181.  
  182.     wftb := GetResource ('Wftb', WIND_Buttons);
  183.  
  184.     errCode := CreateRootControl (window, mRootControl);
  185.  
  186.     vScroll := nil;
  187.     hScroll := nil;
  188.  
  189.  
  190.     mCapInvisibleLabel := GetNewControl (CNTL_CapInvisible, window);
  191.     SetWindowItemFont (mCapInvisibleLabel, wftb, 1);
  192.     SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
  193.  
  194.     mInvisibleHandle := GetNewControl (CNTL_Invisible, window);
  195.     SetWindowItemFont (mInvisibleHandle, wftb, 2);
  196.  
  197.     mStandardHandle := GetNewControl (CNTL_Standard, window);
  198.     SetWindowItemFont (mStandardHandle, wftb, 3);
  199.  
  200.     mDefaultHandle := GetNewControl (CNTL_Default, window);
  201.     SetWindowItemFont (mDefaultHandle, wftb, 4);
  202.     SetDefaultState (mDefaultHandle, true);
  203.  
  204.     mBevelHandle := GetNewControl (CNTL_Bevel, window);
  205.     SetWindowItemFont (mBevelHandle, wftb, 5);
  206.  
  207.     mButtonHandle := GetNewControl (CNTL_Button, window);
  208.     errCode := EmbedControl (mButtonHandle, mBevelHandle);
  209.     SetWindowItemFont (mButtonHandle, wftb, 6);
  210.     errCode := SetBevelButtonGraphicAlignment (mButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  211.  
  212.     mNextHandle := GetNewControl (CNTL_Next, window);
  213.     errCode := EmbedControl (mNextHandle, mBevelHandle);
  214.     SetWindowItemFont (mNextHandle, wftb, 7);
  215.     errCode := SetBevelButtonTextPlacement (mNextHandle, kControlBevelButtonPlaceToRightOfGraphic);
  216.     errCode := SetBevelButtonTextAlignment (mNextHandle, kControlBevelButtonAlignTextFlushLeft, 0);
  217.     errCode := SetBevelButtonGraphicAlignment (mNextHandle, kControlBevelButtonAlignLeft, 0, 0);
  218.  
  219.     mNext2Handle := GetNewControl (CNTL_Next2, window);
  220.     errCode := EmbedControl (mNext2Handle, mBevelHandle);
  221.     SetWindowItemFont (mNext2Handle, wftb, 8);
  222.     errCode := SetBevelButtonTextPlacement (mNext2Handle, kControlBevelButtonPlaceBelowGraphic);
  223.     errCode := SetBevelButtonTextAlignment (mNext2Handle, kControlBevelButtonAlignTextCenter, 0);
  224.     errCode := SetBevelButtonGraphicAlignment (mNext2Handle, kControlBevelButtonAlignTop, 0, 0);
  225.  
  226.     mGraphicHandle := GetNewControl (CNTL_Graphic, window);
  227.     SetWindowItemFont (mGraphicHandle, wftb, 9);
  228.  
  229.     mCapcicnLabel := GetNewControl (CNTL_Capcicn, window);
  230.     errCode := EmbedControl (mCapcicnLabel, mGraphicHandle);
  231.     SetWindowItemFont (mCapcicnLabel, wftb, 10);
  232.     SetControlFromTEXT (mCapcicnLabel, TEXT_Capcicn);
  233.  
  234.     mRightHandle := GetNewControl (CNTL_Right, window);
  235.     errCode := EmbedControl (mRightHandle, mGraphicHandle);
  236.     SetWindowItemFont (mRightHandle, wftb, 11);
  237.  
  238.     mCapicl8Label := GetNewControl (CNTL_Capicl8, window);
  239.     errCode := EmbedControl (mCapicl8Label, mGraphicHandle);
  240.     SetWindowItemFont (mCapicl8Label, wftb, 12);
  241.     SetControlFromTEXT (mCapicl8Label, TEXT_Capicl8);
  242.  
  243.     mLightHandle := GetNewControl (CNTL_Light, window);
  244.     errCode := EmbedControl (mLightHandle, mGraphicHandle);
  245.     SetWindowItemFont (mLightHandle, wftb, 13);
  246.  
  247.     mCapICNLabel := GetNewControl (CNTL_CapICN, window);
  248.     errCode := EmbedControl (mCapICNLabel, mGraphicHandle);
  249.     SetWindowItemFont (mCapICNLabel, wftb, 14);
  250.     SetControlFromTEXT (mCapICNLabel, TEXT_CapICN);
  251.  
  252.     mRight2Handle := GetNewControl (CNTL_Right2, window);
  253.     errCode := EmbedControl (mRight2Handle, mGraphicHandle);
  254.     SetWindowItemFont (mRight2Handle, wftb, 15);
  255.  
  256.     mCapicl9Label := GetNewControl (CNTL_Capicl9, window);
  257.     errCode := EmbedControl (mCapicl9Label, mGraphicHandle);
  258.     SetWindowItemFont (mCapicl9Label, wftb, 16);
  259.     SetControlFromTEXT (mCapicl9Label, TEXT_Capicl9);
  260.  
  261.     mButton2Handle := GetNewControl (CNTL_Button2, window);
  262.     errCode := EmbedControl (mButton2Handle, mGraphicHandle);
  263.     SetWindowItemFont (mButton2Handle, wftb, 17);
  264.  
  265.     mRight3Handle := GetNewControl (CNTL_Right3, window);
  266.     errCode := EmbedControl (mRight3Handle, mGraphicHandle);
  267.     SetWindowItemFont (mRight3Handle, wftb, 18);
  268.  
  269.     mCapPICTLabel := GetNewControl (CNTL_CapPICT, window);
  270.     errCode := EmbedControl (mCapPICTLabel, mGraphicHandle);
  271.     SetWindowItemFont (mCapPICTLabel, wftb, 19);
  272.     SetControlFromTEXT (mCapPICTLabel, TEXT_CapPICT);
  273.  
  274.     mRect3DHandle := GetNewControl (CNTL_Rect3D, window);
  275.     SetWindowItemFont (mRect3DHandle, wftb, 20);
  276.  
  277.     mLeftIconHandle := GetNewControl (CNTL_LeftIcon, window);
  278.     SetWindowItemFont (mLeftIconHandle, wftb, 21);
  279.  
  280.     mRightIconHandle := GetNewControl (CNTL_RightIcon, window);
  281.     SetWindowItemFont (mRightIconHandle, wftb, 22);
  282.  
  283.     mTitledPICTHandle := GetNewControl (CNTL_TitledPICT, window);
  284.     SetWindowItemFont (mTitledPICTHandle, wftb, 23);
  285.  
  286.     errCode := AdvanceKeyboardFocus (window);
  287.  
  288.     ShowWindow (window);
  289. end;
  290.  
  291. {----------}
  292. Procedure Buttons.Close;
  293. begin
  294.     mData.RemoveResponder (self);
  295.  
  296.     EverythingDoc (mDoc).mButtonsPtr := nil;
  297.     SetInfo (nil);
  298.     HideWindow (mWindow);
  299.     DisposeWindow (mWindow);
  300.  
  301.     Dispose (self);
  302. end;
  303.  
  304. {----------}
  305. Procedure Buttons.Control (
  306.     whichControl:    ControlHandle;
  307.     whichPart:        integer;
  308.     where:            Point);
  309. var
  310.     bounds:            Rect;
  311.     newValue:        integer;
  312.     partcode:        SInt16;
  313. begin
  314.     ExitCurField ();
  315.  
  316.     if whichControl = mInvisibleHandle then begin
  317.         if TrackClick (mInvisibleHandle, where) then begin
  318.         end;
  319.     end;
  320.     if whichControl = mStandardHandle then begin
  321.         if TrackClick (mStandardHandle, where) then begin
  322.         end;
  323.     end;
  324.     if whichControl = mDefaultHandle then begin
  325.         if TrackClick (mDefaultHandle, where) then begin
  326.         end;
  327.     end;
  328.     if whichControl = mButtonHandle then begin
  329.         if TrackClick (mButtonHandle, where) then begin
  330.         end;
  331.     end;
  332.     if whichControl = mNextHandle then begin
  333.         if TrackClick (mNextHandle, where) then begin
  334.         end;
  335.     end;
  336.     if whichControl = mNext2Handle then begin
  337.         if TrackClick (mNext2Handle, where) then begin
  338.         end;
  339.     end;
  340.     if whichControl = mRightHandle then begin
  341.         if TrackClick (mRightHandle, where) then begin
  342.         end;
  343.     end;
  344.     if whichControl = mLightHandle then begin
  345.         if TrackClick (mLightHandle, where) then begin
  346.         end;
  347.     end;
  348.     if whichControl = mRight2Handle then begin
  349.         if TrackClick (mRight2Handle, where) then begin
  350.         end;
  351.     end;
  352.     if whichControl = mButton2Handle then begin
  353.         if TrackClick (mButton2Handle, where) then begin
  354.         end;
  355.     end;
  356.     if whichControl = mRight3Handle then begin
  357.         if TrackClick (mRight3Handle, where) then begin
  358.         end;
  359.     end;
  360.     if whichControl = mRect3DHandle then begin
  361.         if TrackClick (mRect3DHandle, where) then begin
  362.         end;
  363.     end;
  364.     if whichControl = mLeftIconHandle then begin
  365.         if TrackClick (mLeftIconHandle, where) then begin
  366.         end;
  367.     end;
  368.     if whichControl = mRightIconHandle then begin
  369.         if TrackClick (mRightIconHandle, where) then begin
  370.         end;
  371.     end;
  372.     if whichControl = mTitledPICTHandle then begin
  373.         if TrackClick (mTitledPICTHandle, where) then begin
  374.         end;
  375.     end;
  376. end;
  377.  
  378. {----------}
  379. Procedure Buttons.DataChanged (
  380.     inDataID:        longint);
  381. begin
  382. End;
  383.  
  384. {----------}
  385. Procedure Buttons.MouseIn (
  386.     where:            Point;
  387.     modifiers:        integer);
  388. var
  389.     bounds:            Rect;
  390. begin
  391. end;
  392.  
  393. {----------}
  394. Procedure Buttons.ExitCurField;
  395. var
  396.     errCode:    OSErr;
  397.     focus:        ControlHandle;
  398. begin
  399.     errCode := GetKeyboardFocus (mWindow, focus);
  400.  
  401.     if focus = nil then begin
  402.         { nothing to exit }
  403.  
  404.     end;
  405.     inherited ExitCurField;
  406. end;
  407.  
  408. {----------}
  409. Procedure Buttons.TypeIn (
  410.     charCode:    SInt16);
  411. var
  412.     ch:            char;
  413.     errCode:    OSErr;
  414.     focus:        ControlHandle;
  415.     keyCode:    SInt16;
  416.     partcode:    SInt16;
  417. begin
  418.     errCode := GetKeyboardFocus (mWindow, focus);
  419.  
  420.     ch := chr (charCode);
  421.     if (ch = charEnter)
  422.     |  (ch = charReturn) then begin
  423.         ExitCurField;
  424.         SimulateClick (mDefaultHandle);
  425.     end else if ch = charEsc then begin
  426.     end else if ch = charTab then begin
  427.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  428.     end else if focus <> nil then begin
  429.         keyCode := BAnd (curEvent.message, keyCodeMask);
  430.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  431.         mDoc.mEngine.SetDirty;
  432.     end else begin
  433.         SysBeep (1);
  434.     end;
  435. end;
  436.  
  437. {----------}
  438. Procedure Buttons.Resize;
  439. begin
  440.     { application-specific code to resize items in window }
  441. end;
  442.  
  443. {----------}
  444. Procedure Buttons.Scroll (
  445.     newValue:    integer;
  446.     oldValue:    integer);
  447. begin
  448.     { application-specific code to scroll window }
  449.     if gWhichScroll = vScroll then begin
  450.     end else begin    { horizontal }
  451.     end;
  452. end;
  453.  
  454. {----------}
  455. Procedure Buttons.DoUndo;
  456. begin
  457. end; {DoUndo}
  458.  
  459. {----------}
  460. Procedure Buttons.DoCut;
  461. var
  462.     curTE:        TEHandle;
  463. begin
  464.     curTE := GetCurTE ();
  465.  
  466.     if curTE <> nil then begin
  467.         TECut (curTE);
  468.         mDoc.mEngine.SetDirty;
  469.         scrapDirty := true;
  470.     end;
  471. end; {DoCut}
  472.  
  473. {----------}
  474. Procedure Buttons.DoCopy;
  475. var
  476.     curTE:        TEHandle;
  477. begin
  478.     curTE := GetCurTE ();
  479.  
  480.     if curTE <> nil then begin
  481.         TECopy (curTE);
  482.         scrapDirty := true;
  483.     end;
  484. end; {DoCopy}
  485.  
  486. {----------}
  487. Procedure Buttons.DoPaste;
  488. var
  489.     curTE:        TEHandle;
  490. begin
  491.     curTE := GetCurTE ();
  492.  
  493.     if curTE <> nil then begin
  494.         TEPaste (curTE);
  495.         mDoc.mEngine.SetDirty;
  496.     end;
  497. end; {DoPaste}
  498.  
  499. {----------}
  500. Procedure Buttons.DoClear;
  501. var
  502.     curTE:        TEHandle;
  503. begin
  504.     curTE := GetCurTE ();
  505.  
  506.     if curTE <> nil then begin
  507.         TEDelete (curTE);
  508.         mDoc.mEngine.SetDirty;
  509.     end;
  510. end; {DoClear}
  511.  
  512. {----------}
  513. Procedure Buttons.DoSelectAll;
  514. var
  515.     curTE:        TEHandle;
  516. begin
  517.     curTE := GetCurTE ();
  518.  
  519.     if curTE <> nil then begin
  520.         TESetSelect (0, 32767, curTE);
  521.     end;
  522. end; {DoSelectAll}
  523.  
  524. {----------}
  525. Procedure Buttons.DoShowClipboard;
  526. begin
  527. end; {DoShowClipboard}
  528.  
  529. {----------}
  530. Function Buttons.DoCommand (
  531.     inCommand:        longint): Boolean;
  532. begin
  533.     DoCommand := true;
  534.     case inCommand of
  535.         cmdUndo:
  536.                 DoUndo;
  537.         cmdCut:
  538.                 DoCut;
  539.         cmdCopy:
  540.                 DoCopy;
  541.         cmdPaste:
  542.                 DoPaste;
  543.         cmdClear:
  544.                 DoClear;
  545.         cmdSelectAll:
  546.                 DoSelectAll;
  547.         cmdShowClipboard:
  548.                 DoShowClipboard;
  549.  
  550.         otherwise
  551.                 DoCommand := false;
  552.     end; {case}
  553. end;
  554.  
  555. end.
  556.